package com.ymttest.database.sqlwapper;

import java.util.List;

import com.ymt.core.tool.Logger;
import com.ymt.database.SqlManager;
import com.ymttest.database.model.YmtCatalogs;
import com.ymttest.utils.EnvSetup;

/************************************************************************************
 * @File name : YmtUserWapper.java
 * @Author : zhouyi
 * @Date : 2015年4月2日
 * @Copyright : 洋码头
 ************************************************************************************/
public class YmtCatalogsWapper {
	SqlManager manage;

	public YmtCatalogsWapper() {
		manage = new SqlManager("ymt" + EnvSetup.getEnv());
	}

	/**
	 * 根据SproductId查询YmtCatalogs
	 * 
	 * @param id
	 *            SproductId
	 * @return YmtCatalogs
	 * @throws InterruptedException
	 */
	public YmtCatalogs selectBySproductId(String id) throws InterruptedException {

		List<YmtCatalogs> catalogs = manage.getSelectResults(
				"com.ymttest.database.mapping.YmtCatalogsMapper.selectBySproductId", id);

		// manage.close();
		return catalogs.get(0);
	}

	/**
	 * insert 一条YmtCatalogs记录
	 * 
	 * @param record
	 *            YmtCatalogs
	 * @return
	 * @throws InterruptedException
	 */
	public int insertYmtCatalogs(YmtCatalogs record) {
		int i = manage.insert("com.ymttest.database.mapping.YmtCatalogsMapper.insert", record);
		manage.commit();
		// manage.close();
		return i;
	}

	/**
	 * 查询YmtCatalogs
	 * 
	 * @param id
	 *            SproductId
	 * @return YmtCatalogs
	 * @throws InterruptedException
	 */
	public List<String> selectCatalogIdList() throws InterruptedException {

		List<String> catalogs = manage.getSelectResults(
				"com.ymttest.database.mapping.YmtCatalogsMapper.selectCatalogIdList", null);

		// manage.close();
		return catalogs;
	}

	/**
	 * 关闭数据库连接
	 */
	public void close() {
		manage.close();
	}

	@Override
	protected void finalize() throws Throwable {
		this.close();
		manage = null;
		super.finalize();
	}

	public static void main(String args[]) {
		try {
			 Logger.debug(new
			 YmtCatalogsWapper().selectBySproductId("91dc95df-5b96-40a1-9050-cb7c5417fb83").getScatalogid());
//			List<String> list = new YmtCatalogsWapper().selectCatalogIdList();
//			for (String s : list) {
//				Logger.debug(s);
//			}
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
}
